home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ncsa / Mac / Telnet2.6 / prerelease / d3 / Telnet2.6.1d3.src.sit.hqx / Telnet 2.6.1d3 source / source / main / Connections.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-27  |  18.9 KB  |  625 lines

  1. /****************************************************************
  2. *    NCSA Telnet for the Macintosh                                *
  3. *                                                                *
  4. *    National Center for Supercomputing Applications                *
  5. *    Software Development Group                                    *
  6. *    152 Computing Applications Building                            *
  7. *    605 E. Springfield Ave.                                        *
  8. *    Champaign, IL  61820                                        *
  9. *                                                                *
  10. *    Copyright (c) 1986-1993,                                    *
  11. *    Board of Trustees of the University of Illinois                *
  12. *****************************************************************/
  13.  
  14. #ifdef MPW
  15. #pragma segment 4
  16. #endif
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21.  
  22. #include "TelnetHeader.h"
  23.  
  24. #include "telneterrors.h"
  25. #include "DlogUtils.proto.h"
  26.  
  27. #include "wind.h"
  28. #include "event.proto.h"
  29.  
  30. #include "rsmac.proto.h"
  31. #include "vsdata.h"
  32. #include "vskeys.h"
  33. #include "vsinterf.proto.h"
  34. #include "vgtek.proto.h"
  35. #include "tekrgmac.proto.h"
  36. #include "vr.h"
  37. #include "vrrgmac.proto.h" 
  38. #include "network.proto.h"
  39. #include "mydnr.proto.h"
  40. #include "InternalEvents.h"
  41. #include "menuseg.proto.h"
  42. #include "maclook.proto.h"
  43. #include "parse.proto.h"
  44. #include "parse.h"
  45. #include "configure.proto.h"
  46.  
  47. #include "prefs.proto.h"
  48. #include "popup.h"
  49. #include "popup.proto.h"
  50.  
  51. #include "Connections.proto.h"
  52. #include "tnae.h"
  53. #include "authencrypt.h"
  54. #include "authencrypt.proto.h"
  55. #include "wdefpatch.proto.h"
  56.  
  57. /*    These are all of the variables we need... */
  58.  
  59. extern    Cursor    *theCursors[NUMCURS];        /* all the cursors in a nice bundle */
  60. extern    WindRec    *screens;
  61. extern    short    scrn;
  62. extern    short    nNational;                // Number of user-installed translation tables
  63. extern    MenuHandle    myMenus[];
  64. extern    Boolean    authOK;
  65. extern    Boolean    encryptOK;
  66.  
  67. static    pascal short POCdlogfilter( DialogPtr dptr, EventRecord *evt, short *item);
  68. PROTO_UPP(POCdlogfilter, ModalFilter);
  69.  
  70. void OpenPortSpecial(MenuHandle menuh, short item)
  71. {
  72.     ConnInitParams        **theParams;
  73.     Boolean                success;
  74.     Str255                scratchPstring;
  75.     
  76.     GetItem(menuh, item, scratchPstring);
  77.     
  78.     theParams = NameToConnInitParams(scratchPstring);
  79.     if (theParams == NULL) {
  80.         OutOfMemory(1020);
  81.         return;
  82.         }
  83.         
  84.     success = CreateConnectionFromParams(theParams);
  85. }
  86.  
  87. SIMPLE_UPP(POCdlogfilter, ModalFilter);
  88. pascal short POCdlogfilter( DialogPtr dptr, EventRecord *evt, short *item)
  89. {
  90.     short key;
  91.  
  92.     if (evt->what == keyDown) {
  93.         key = evt->message & charCodeMask;
  94.         if ( ((key == 'F') || (key == 'f')) && (evt->modifiers & cmdKey) ) {
  95.             *item = NCftpcheckbox;
  96.             return(-1);
  97.             }
  98.         if ( ((key == 'A') || (key == 'a')) && (evt->modifiers & cmdKey) ) {
  99.             *item = NCauthenticate;
  100.             return(-1);
  101.             }
  102.         if ( ((key == 'E') || (key == 'e')) && (evt->modifiers & cmdKey) ) {
  103.             *item = NCencrypt;
  104.             return(-1);
  105.             }
  106.         }
  107.     
  108.     return(DLOGwOK_Cancel(dptr, evt, item));
  109. }
  110.  
  111. void    PresentOpenConnectionDialog(void)
  112. {
  113.     ConnInitParams    **InitParams;
  114.     DialogPtr        dptr;
  115.     short            ditem, scratchshort;
  116.     static long        numWind = 1;
  117.     Boolean            success;
  118.     long            scratchlong;
  119.     Str255            scratchPstring;
  120.     Handle            ItemHandle;
  121.     SessionPrefs    **defaultSessHdl;
  122.     MenuHandle        SessPopupHdl;
  123.     Rect            scratchRect;
  124.     Point            SessPopupLoc;
  125.     
  126.     SetCursor(theCursors[normcurs]);
  127.     
  128.     dptr = GetNewMyDialog(NewCnxnDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  129.     if (dptr == NULL) {
  130.         OutOfMemory(1000);
  131.         return;
  132.         }
  133.         
  134.     ditem = 3;
  135.     
  136.     SessPopupHdl = NewMenu(668, "\pSession:");
  137.     if (SessPopupHdl == NULL) {
  138.         OutOfMemory(1000);
  139.         DisposeDialog(dptr);
  140.         return;
  141.         }
  142.         
  143.     UseResFile(TelInfo->SettingsFile);
  144.     AddResMenu(SessPopupHdl, SESSIONPREFS_RESTYPE);
  145.     EnableItem(SessPopupHdl, 0);        // Make sure the entire menu is enabled
  146.     
  147.     GetDItem(dptr, NCsesspopup, &scratchshort, &ItemHandle, &scratchRect);
  148.     SessPopupLoc.h = scratchRect.left;
  149.     SessPopupLoc.v = scratchRect.top;
  150.     SetPort(dptr);
  151.     LocalToGlobal(&SessPopupLoc);
  152.     
  153.     // Get default auth/encrypt settings from default session
  154.     defaultSessHdl = GetDefaultSession();
  155.     HLock((Handle)defaultSessHdl);
  156.  
  157.     BlockMove("\p<Default>", scratchPstring, 15);
  158.     GetHostNameFromSession(scratchPstring);
  159.     SetTEText(dptr, NChostname, scratchPstring);
  160.     SelIText(dptr, NChostname, 0, 32767);
  161.  
  162.     SetCntrl(dptr, NCauthenticate, (**defaultSessHdl).authenticate && authOK);
  163.     SetCntrl(dptr, NCencrypt, (**defaultSessHdl).encrypt && encryptOK);
  164.     DisposeHandle((Handle)defaultSessHdl);
  165.         
  166.     setSessStates(dptr);
  167.  
  168.     while (ditem > NCcancel) {
  169.         ModalDialog(POCdlogfilterUPP, &ditem);
  170.         switch(ditem) {
  171.             case    NCftpcheckbox:
  172.             case    NCauthenticate:
  173.             case    NCencrypt:
  174.                 GetDItem(dptr, ditem, &scratchshort, &ItemHandle, &scratchRect);
  175.                 if ((**(ControlHandle)ItemHandle).contrlHilite == 0) {    // if control not disabled
  176.                     FlipCheckBox(dptr, ditem);
  177.                     setSessStates(dptr);
  178.                 }
  179.                 break;
  180.  
  181.             case    NCsesspopup:
  182.                 InsertMenu(SessPopupHdl, hierMenu);
  183.                 CalcMenuSize(SessPopupHdl);
  184.                 scratchlong = PopUpMenuSelect(SessPopupHdl, SessPopupLoc.v,
  185.                                                 SessPopupLoc.h, 0);
  186.                 DeleteMenu(668);
  187.                 if (scratchlong) {
  188.                     scratchshort = scratchlong & 0xFFFF; //    Apple sez ignore the high word
  189.                     GetItem(SessPopupHdl, scratchshort, scratchPstring);
  190.                     SetTEText(dptr, NChostname, scratchPstring);
  191.                     SelIText(dptr, NChostname, 0, 32767);
  192.                     }
  193.                 break;
  194.                                 
  195.             default:
  196.                 break;
  197.             } // switch
  198.         } // while
  199.     
  200.     DisposeMenu(SessPopupHdl);
  201.     
  202.     if (ditem == NCcancel) {
  203.         DisposeDialog(dptr);
  204.         return;
  205.         }
  206.     
  207.     GetTEText(dptr, NChostname, scratchPstring);
  208.     if (!Length(scratchPstring)) {
  209.         DisposeDialog(dptr);
  210.         return;
  211.         }
  212.         
  213.     InitParams = NameToConnInitParams(scratchPstring);
  214.     if (InitParams == NULL) {
  215.         OutOfMemory(1000);
  216.         DisposeDialog(dptr);
  217.         return;
  218.         }
  219.  
  220.     HLock((Handle)InitParams);
  221.     HLock((Handle)(**InitParams).session);
  222.     GetTEText(dptr, NCwindowname, scratchPstring);
  223.  
  224.     // Copy over the user specified window name.  If blank, CreateConnectionFromParams 
  225.     // will copy the hostname to the windowname and append a number.
  226.     if (Length(scratchPstring)) 
  227.         BlockMove(scratchPstring, (**InitParams).WindowName,
  228.                     (Length(scratchPstring) > 63) ? 64 : (Length(scratchPstring) + 1));
  229.  
  230.     if (GetCntlVal(dptr, NCftpcheckbox)) {
  231.         (**InitParams).ftpstate = 1;
  232.         (**(**InitParams).session).halfdup = 1;        /* BYU */
  233.         }
  234.      if (GetCntlVal(dptr, NCauthenticate))
  235.           (**(**InitParams).session).authenticate = 1;
  236.      else
  237.          (**(**InitParams).session).authenticate = 0;
  238.      if (GetCntlVal(dptr, NCencrypt))
  239.           (**(**InitParams).session).encrypt = 1;
  240.      else
  241.          (**(**InitParams).session).encrypt = 0;
  242.         
  243.     HUnlock((Handle)(**InitParams).session);
  244.     HUnlock((Handle)InitParams);
  245.         
  246.     DisposeDialog(dptr);
  247.     
  248.     success = CreateConnectionFromParams(InitParams);
  249. }
  250.  
  251. // Set states of session checkboxes
  252. void setSessStates (DialogPtr dptr)
  253. {
  254.     if (GetCntlVal(dptr, NCftpcheckbox)  || !authOK)
  255.         Hilite(dptr, NCauthenticate, 255);
  256.     else
  257.         Hilite(dptr, NCauthenticate, 0);
  258.         
  259.     if (GetCntlVal(dptr, NCauthenticate)) {
  260.         Hilite(dptr, NCftpcheckbox, 255);
  261.         Hilite(dptr, NCencrypt, (encryptOK)? 0 : 255);
  262.     } else {
  263.         Hilite(dptr, NCftpcheckbox, 0);
  264.         Hilite(dptr, NCencrypt, 255);
  265.         SetCntrl(dptr, NCencrypt, false);
  266.     }
  267. }
  268.         
  269. Boolean CreateConnectionFromParams( ConnInitParams **Params)
  270. {
  271.     short            scratchshort, fontnumber, offset;
  272.     static short    numWind = 1, stagNum = 1;
  273.     SessionPrefs    *SessPtr;
  274.     TerminalPrefs    *TermPtr;
  275.     short            cur;
  276.     Str32            numPstring;
  277.     Str255            scratchPstring;
  278.     Boolean            scratchBoolean;
  279.     
  280.     SetCursor(theCursors[watchcurs]);                    /* We may be here a bit */
  281.  
  282.     // Check if we have the max number of sessions open
  283.     if (TelInfo->numwindows == MaxSess) return(FALSE);
  284.     
  285.     cur = TelInfo->numwindows;            /* Adjust # of windows and get this window's number */
  286.     TelInfo->numwindows++;
  287.     screens[cur].active = CNXN_NOTINUSE;    // Make sure it is marked as dead (in case we
  288.                                         // abort screen creation after initiating DNR.
  289.                                         // That way CompleteConnectionOpening will know
  290.                                         // we didn't make it.
  291.     HLockHi((Handle)Params);
  292.     HLockHi((Handle)(**Params).terminal);
  293.     HLockHi((Handle)(**Params).session);
  294.     SessPtr = *((**Params).session);
  295.     TermPtr = *((**Params).terminal);
  296.  
  297.     if (Length((**Params).WindowName) == 0) {
  298.         BlockMove((**(**Params).session).hostname, (**Params).WindowName, 
  299.                     Length((**(**Params).session).hostname)+1);
  300.         NumToString(numWind++, numPstring);
  301.         pstrcat((**Params).WindowName, "\p ");
  302.         pstrcat((**Params).WindowName, numPstring);    // tack the number onto the end.
  303.         }
  304.         
  305.     // Get the IP for the host while we set up the connection
  306.     if (DoTheDNR(SessPtr->hostname, cur) != noErr) {
  307.         OutOfMemory(1010);
  308.         DisposeHandle((Handle)(**Params).terminal);
  309.         DisposeHandle((Handle)(**Params).session);
  310.         DisposeHandle((Handle)Params);
  311.         TelInfo->numwindows--;
  312.         updateCursor(1);
  313.         return(FALSE);
  314.         }
  315.         
  316.     DoTheMenuChecks();
  317.     
  318.       screens[cur].authenticate = SessPtr->authenticate && authOK;
  319.       screens[cur].encrypt = SessPtr->encrypt && encryptOK;
  320.  
  321.     screens[cur].aedata = NULL;
  322.      
  323.      for (scratchshort = 0; scratchshort < sizeof(screens[cur].myopts); scratchshort++) {
  324.         screens[cur].myopts[scratchshort] = 0;
  325.         screens[cur].hisopts[scratchshort] = 0;        
  326.     }    
  327.     screens[cur].cannon[0] = '\0';
  328.  
  329.     screens[cur].vtemulation = TermPtr->vtemulation;
  330.     screens[cur].forcesave = SessPtr->forcesave;
  331.     screens[cur].lineAllow = SessPtr->linemode;
  332.     screens[cur].eightbit = TermPtr->eightbit;    // Is this necessary?
  333.     screens[cur].portNum = SessPtr->port;
  334.     screens[cur].emacsmeta = TermPtr->emacsmetakey;
  335.     screens[cur].Xterm = TermPtr->Xtermsequences;
  336.     
  337.     screens[cur].port = -1;                // netxopen will take care of this
  338.  
  339.     screens[cur].lmode = 0;
  340.     for (scratchshort=0; scratchshort<= SLC_ARRAY_SIZE; scratchshort++)
  341.         screens[cur].slc[scratchshort] = -1;
  342.     screens[cur].slc[SLC_IP] = 3;
  343.     screens[cur].slc[SLC_EC] = 127;
  344.     screens[cur].slc[SLC_EL] = 21;
  345.     screens[cur].slc[SLC_EOF] = 4;
  346.     screens[cur].slc[SLC_ABORT] = 3;
  347.     screens[cur].slc[SLC_SUSP] = 26; 
  348.  
  349.     // If the caller has not specified a window location, come up with our own.
  350.     // This function can possibly stagger windows right off the screen.
  351.     if((**Params).WindowLocation.top == 0) {
  352.         offset = ((gApplicationPrefs->StaggerWindows == TRUE) ? 10 : 2) * (stagNum++);
  353.         (**Params).WindowLocation.top = GetMBarHeight() + 10 + offset;
  354.         (**Params).WindowLocation.left  = offset;
  355.         (**Params).WindowLocation.bottom= 30000 + offset;
  356.         (**Params).WindowLocation.right = 30000 + offset;
  357.         }
  358.         
  359.     GetFNum(TermPtr->DisplayFont, &fontnumber);
  360.     
  361.     screens[cur].vs = RSnewwindow( &((**Params).WindowLocation), TermPtr->numbkscroll, TermPtr->vtwidth,
  362.                                     TermPtr->vtheight, (**Params).WindowName, TermPtr->vtwrap,
  363.                                     fontnumber, TermPtr->fontsize, 0,
  364.                                     1,
  365.                                     SessPtr->forcesave);
  366.                                     
  367.     if (screens[cur].vs <0 ) {     /* we have a problem opening up the virtual screen */
  368.         OutOfMemory(1011);
  369.         DisposeHandle((Handle)(**Params).terminal);
  370.         DisposeHandle((Handle)(**Params).session);
  371.         DisposeHandle((Handle)Params);
  372.         TelInfo->numwindows--;
  373.         DoTheMenuChecks();
  374.         updateCursor(1);
  375.         return(FALSE);
  376.         }
  377.  
  378.     screens[cur].wind = RSgetwindow( screens[cur].vs);
  379.     ((WindowPeek)screens[cur].wind)->windowKind = WIN_CNXN;
  380.     
  381.     /*
  382.      * Attach our extra part to display encryption status
  383.      */
  384.     PatchWindowWDEF(screens[cur].wind, &screens[cur]);
  385.  
  386.     screens[cur].arrowmap = TermPtr->emacsarrows;          /* MAT -- save our arrow setting */
  387.     screens[cur].maxscroll= TermPtr->numbkscroll;
  388.     screens[cur].rows = TermPtr->vtheight;                /* BYU 2.4.16 */
  389.     screens[cur].bsdel = SessPtr->bksp;
  390.     screens[cur].crmap = SessPtr->crmap;
  391.     screens[cur].tekclear = SessPtr->tekclear;
  392.     screens[cur].ESscroll= TermPtr->clearsave;
  393.     screens[cur].tektype = SessPtr->tektype;
  394.     screens[cur].wrap = TermPtr->vtwrap;
  395.     screens[cur].pgupdwn = TermPtr->MATmappings;        /* JMB: map pgup/pgdwn/home/end? */
  396.     screens[cur].width= TermPtr->vtwidth;
  397.     screens[cur].TELstop = SessPtr->skey;
  398.     screens[cur].TELgo = SessPtr->qkey;
  399.     screens[cur].TELip = SessPtr->ckey;
  400.     BlockMove((Ptr)SessPtr->hostname, screens[cur].machine, Length(SessPtr->hostname)+1);
  401.     BlockMove(TermPtr->AnswerBackMessage, screens[cur].answerback, 32);
  402.     screens[cur].termstate = VTEKTYPE;
  403.     screens[cur].naws = 0;                                /* NCSA - set default NAWS to zero */
  404.     screens[cur].xfer=0;
  405.     screens[cur].telstate=0;
  406.     screens[cur].timing=0;
  407.     screens[cur].curgraph=-1;                /* No graphics screen */
  408.     screens[cur].ftpport = -1;                /* BYU - No additional FTP port opened yet */
  409.     screens[cur].clientflags = 0;            /* BYU */
  410.     screens[cur].kblen = 0;                /* nothing in the buffer */
  411.     screens[cur].enabled = 1;            /* Gotta be enabled to start with */
  412.     screens[cur].Ittype = 0;
  413.     screens[cur].Isga = 0;                /* I suppress go ahead = no */
  414.     screens[cur].Usga = 0;                /* U suppress go ahead = no */
  415.  
  416.     screens[cur].ftpstate = (**Params).ftpstate;    /* BYU */
  417.     if ((**Params).ftpstate != 0) {        /* BYU */
  418.         screens[cur].termstate=DUMBTYPE;    /* BYU */
  419.         screens[cur].echo=1;                /* BYU - Echo for ftp */
  420.         screens[cur].halfdup = 1;            /* BYU */
  421.     } else {                            /* BYU */
  422.         screens[cur].termstate=VTEKTYPE;    /* BYU */
  423.         screens[cur].echo = 1;
  424.         screens[cur].halfdup = SessPtr->halfdup;    /* BYU */
  425.     }
  426.     
  427.     screens[cur].national = 0;            // Default to no translation.
  428.     // Now see if the desired translation is available, if not use default translation.
  429.     for(scratchshort = 1; scratchshort <= nNational+1; scratchshort++) {
  430.         GetItem(myMenus[National], scratchshort, scratchPstring);
  431.         if (EqualString(SessPtr->TranslationTable, scratchPstring, TRUE, FALSE))
  432.             screens[cur].national = scratchshort-1;
  433.         }
  434.                 
  435.     
  436.     // Set up paste related variables
  437.     screens[cur].incount = 0;
  438.     screens[cur].outcount = 0;
  439.     screens[cur].outptr = NULL;
  440.     screens[cur].outhand = NULL;
  441.     screens[cur].outlen = 0;
  442.     screens[cur].pastemethod = SessPtr->pastemethod;
  443.     screens[cur].pastesize = SessPtr->pasteblocksize;
  444.     
  445.     scratchBoolean = NewRSsetcolor( screens[cur].vs, 0, TermPtr->nfcolor);
  446.     scratchBoolean = NewRSsetcolor( screens[cur].vs, 1, TermPtr->nbcolor);
  447.     scratchBoolean = NewRSsetcolor( screens[cur].vs, 2, TermPtr->bfcolor);
  448.     scratchBoolean = NewRSsetcolor( screens[cur].vs, 3, TermPtr->bbcolor);
  449.  
  450.     addinmenu(cur, (**Params).WindowName, diamondMark);
  451.     screens[cur].active = CNXN_DNRWAIT;            // Signal we are waiting for DNR.
  452.  
  453.     screens[cur].myInitParams = (Handle)Params;
  454.     HUnlock((Handle)(**Params).terminal);
  455.     HUnlock((Handle)(**Params).session);
  456.     // Params handle must stay locked because interrupt level DNR completion routine needs to deref it
  457.  
  458.     VSscrolcontrol( screens[cur].vs, -1, screens[cur].ESscroll);
  459.  
  460.     updateCursor(1);                            /* Done stalling the user */
  461.     return(TRUE);
  462. }
  463.  
  464. void    CompleteConnectionOpening(short dat, ip_addr the_IP, OSErr DNRerror, char *cname)
  465. {
  466.     ConnInitParams    **Params;
  467.     
  468.     if (screens[dat].active != CNXN_DNRWAIT) return;            // Something is wrong.
  469.     
  470.     Params = (ConnInitParams **)screens[dat].myInitParams;
  471.     
  472.     if (DNRerror == noErr) {
  473.         HLockHi((Handle)(**Params).session);
  474.         if (screens[dat].ftpstate != 0)                 /* BYU - ftp client */
  475.             screens[dat].port  = netxopen(the_IP,HFTP,40);    /* BYU 2.4.15 - open to host name */
  476.         else                                             /* BYU */
  477.             screens[dat].port  = netxopen(the_IP,(**(**Params).session).port,40);/* BYU 2.4.15 - open to host name */
  478.         
  479.         // We need the cannonical hostname for Kerberos. Make best guess if
  480.         // DNR did not return a cname.
  481.         if (cname)
  482.             strncpy(screens[dat].cannon, cname, sizeof(screens[dat].cannon));
  483.         else
  484.             strncpy(screens[dat].cannon, (char *)(**(**Params).session).hostname, sizeof(screens[dat].cannon));
  485.         screens[dat].cannon[sizeof(screens[dat].cannon)-1] = '\0';
  486.         
  487.         DisposeHandle((Handle)(**Params).session);
  488.         DisposeHandle((Handle)(**Params).terminal);
  489.         DisposeHandle((Handle)Params);
  490.         
  491.         if (screens[dat].port <0) {                    /* Handle netxopen fail */
  492.             destroyport(dat);
  493.             }
  494.         screens[dat].active = CNXN_OPENING;
  495.         SetMenuMarkToOpeningForAGivenScreen(dat);    /* Change status mark */
  496.         }
  497.     else
  498.         {    // We should report the real DNR error here!
  499.         Str255        errorString, numberString, numberString2, scratchPstring;
  500.         DialogPtr    theDialog;
  501.         short        message, ditem = 3;
  502.         
  503.         HLockHi((Handle)(**Params).session);
  504.         BlockMove((**(**Params).session).hostname, scratchPstring, Length((**(**Params).session).hostname)+1);
  505.  
  506.         if (DNRerror >= -23048 && DNRerror <= -23041) message = DNRerror + 23050;
  507.         else message = 1;
  508.         
  509.         GetIndString(errorString,DNR_MESSAGES_ID, message);
  510.         NumToString((long)0, numberString);
  511.         NumToString((long)DNRerror, numberString2);
  512.         ParamText(scratchPstring, errorString, numberString, numberString2);
  513.         
  514.         theDialog = GetNewMyDialog(DNRErrorDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  515.         ShowWindow(theDialog);
  516.     
  517.         while (ditem > 1)    ModalDialog(DLOGwOKUPP, &ditem);
  518.         DisposeDialog(theDialog);
  519.  
  520.         DisposeHandle((Handle)(**Params).session);
  521.         DisposeHandle((Handle)(**Params).terminal);
  522.         DisposeHandle((Handle)Params);
  523.         destroyport(dat);
  524.         }
  525. }
  526.  
  527. void destroyport(short wind)
  528. {
  529.     Handle    h;
  530.     short    i,
  531.             callNoWindow=0;
  532.  
  533.     SetCursor(theCursors[watchcurs]);        /* We may be here a while */
  534.  
  535.     if (screens[wind].active == CNXN_ISCORPSE) {
  536.         if (screens[wind].curgraph>-1)
  537.             detachGraphics( screens[wind].curgraph);    /* Detach the Tek screen */
  538.         if (screens[wind].outlen>0) {
  539.             screens[wind].outlen=0;                        /* Kill the remaining send*/
  540.             HUnlock( screens[wind].outhand);            /*  buffer */
  541.             HPurge ( screens[wind].outhand);
  542.             }
  543.         }
  544.  
  545.     if (FrontWindow() == screens[wind].wind)
  546.         callNoWindow=1;
  547.  
  548.     if (screens[wind].aedata != NULL)
  549.         DisposePtr((Ptr)screens[wind].aedata);
  550.  
  551.     /*
  552.      * Get handle to the WDEF patch block, kill the window, and then
  553.      * release the handle.
  554.      */
  555.     h = GetPatchStuffHandle(screens[wind].wind, &screens[wind]);
  556.     RSkillwindow( screens[wind].vs);
  557.     if (h)
  558.         DisposeHandle(h);
  559.  
  560.     screens[wind].active = CNXN_NOTINUSE;
  561.     for (i=wind;i<TelInfo->numwindows-1;i++) {
  562.         screens[i]=screens[i+1];        /* Bump all of the pointers */
  563.         RePatchWindowWDEF(screens[i].wind, &screens[i]);    /* hack hack hack */
  564.         }
  565.     if (scrn>wind) scrn--;                /* Adjust for deleting a lower #ered screen */
  566.  
  567.     TelInfo->numwindows--;                        /* There are now fewer windows */
  568.     extractmenu( wind);                    /* remove from the menu bar */
  569.  
  570.     DoTheMenuChecks();
  571.  
  572. /* BYU 2.4.11 - the call to "NoWindow()" changes "myfrontwindow", 
  573.                 which is used by "updateCursor()", so we reversed 
  574.                 the order of the following two lines. */
  575.     if (callNoWindow) NoWindow();        /* BYU 2.4.11 - Update cursor stuff if front window */
  576.     updateCursor(1);                    /* BYU 2.4.11 - Done stalling the user */
  577.  
  578. } /* destroyport */
  579.  
  580. void removeport(short n)
  581. {
  582.     Str255        scratchPstring;
  583.     
  584.     SetCursor(theCursors[watchcurs]);                /* We may be here a while */
  585.  
  586.     if (screens[n].curgraph>-1)
  587.         detachGraphics( screens[n].curgraph);        /* Detach the Tek screen */
  588.         
  589.     if (screens[n].outlen>0) {
  590.                 screens[n].outlen=0;                /* Kill the remaining send*/
  591.                 HUnlock( screens[n].outhand);        /*  buffer */
  592.                 HPurge ( screens[n].outhand);
  593.                 }
  594.  
  595.     if (VSiscapturing(screens[n].vs))                /* NCSA: close up the capture */
  596.         CloseCaptureFile(screens[n].vs);            /* NCSA */
  597.  
  598.     if (VSisprinting(screens[n].vs))
  599.         ClosePrintingFile(screens[n].vs);
  600.         
  601.     if (!gApplicationPrefs->WindowsDontGoAway)
  602.         destroyport(n);
  603.     else {
  604.         Str255    temp;
  605.         
  606.         GetWTitle(screens[n].wind, scratchPstring);
  607. #ifdef THINK_C
  608.         sprintf((char *)temp, "(%#s)", scratchPstring);
  609. #else
  610.         PtoCstr(scratchPstring);
  611.         sprintf((char *)temp, "(%s)", scratchPstring);
  612. #endif
  613.         CtoPstr((char *)temp);
  614.         SetWTitle(screens[n].wind, temp);
  615.  
  616.         screens[n].port = 32700;
  617.         screens[n].active = CNXN_ISCORPSE;
  618.         }
  619.  
  620.     updateCursor(1);                            /* Done stalling the user */
  621. } /* removeport */
  622.  
  623.  
  624.  
  625.